const jwt = require('jwt-simple')
const jwtEncode = (adminName, secret) => {
  return jwt.encode({
    adminName,
    exp: Date.now() / 1000 + 60 * 60
  }, secret)
}

const jwtDecode = (token, secret) => {
  try {
    const {
      adminName
    } = jwt.decode(token, secret)
    return {
      code: 1,
      adminName
    }
  } catch (e) {
    return {
      code: 0
    }
  }
}

module.exports = {
  jwtEncode,
  jwtDecode
}




